package xyz.wongs.gry.synx.list
/**
 * @ClassName
 * @Description
 * @author WCNGS@QQ.COM
 * @Github <a> https://github.com/rothschil</a>
 * @date 2020/12/21 10:58
 * @Version 1.0.0
 */

// 1、数组

int[] arrays = new int[]{10,28,45,27,2}
Arrays.sort(arrays)
println(" 直接输出数组"+ arrays)
println(" Arrays 数组转换"+ Arrays.toString(arrays))

// 断言当前数组是否为整型数组
assert arrays instanceof int[]
println(" 获取数组长度 "+ arrays.length)

String[] strs = new String[]{"WONGS","@","QQ.COM"}
println(" 首个元素 "+ strs.first() + " ；最后元素 "+ strs.last())


// 2、列表
def list = ["WONGS","@","QQ.COM"]
// 2.1 添加元素
list << "QQ邮箱"
list.add("163邮箱")
println("打印列表 "+ list)

// 2.2 迭代

list.each {
    println("列表内容 -> "+it)
}

list.eachWithIndex{ entry, i ->
    println(i+" 列表内容 -> "+entry)
}

// 3、Set

def sets = ["WONGS@QQ.COM","WCNGS@163.COM","IWCNGS@GMAIL.COM","WONGS@QQ.COM","WONGS@HOTMAIL.COM"] as Set
println("Clazz is  "+ sets.class)

sets.eachWithIndex{  entry,  i ->
    println(i+" 列表内容 -> "+entry)
}

// 4、Map
def maps = [QQ:"WONGS@QQ.COM",163:"WCNGS@163.COM",GMAIL:"IWCNGS@GMAIL.COM"]
println("Clazz is  "+ sets.class)

// 遍歷
println("遍歷 1  "+ maps['163'])
println("遍歷 2  "+ maps.QQ)

// 添加元素
maps << [189:"189@189.COM"]
// 迭代
maps.eachWithIndex{  entry, i ->
    println("index= "+ i+" ,Key = "+entry.getKey()+" ;Value = "+ entry.getValue())
}

// 5、集合嵌套

def listMaps =[
        [QQ:"IWONGS@QQ.COM",GMAIL:"IWCNGS@GMAIL.COM"],
        [QQ:"WONGS@QQ.COM",163:"WCNGS@163.COM"],null
]

println("打印内容  "+ listMaps)
// 获取指定 数据key的内容
println("打印内容  "+ listMaps.QQ)
// 可以匹配最后的 null
println("打印内容  "+ listMaps*.QQ)
